﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
//using System.Linq;
using System.Text;
using System.Windows.Forms;

// Referencia para poder mostrar la lista de impresoras
using System.Drawing.Printing; 

namespace Ticket
{
	// se agrega la siguiente referencia para enviar texto a impresora
	using System.Runtime.InteropServices;
    using System.Threading;
    using System.Globalization;

	public partial class frmPrinters : Form
	{
		public frmPrinters()
		{
			InitializeComponent();
		}

		#region Lista de Impresoras
		// Crea lista de impresoras instaladas
		private void frmPrinters_Load(object sender, EventArgs e)
		{
			foreach (string printerName in PrinterSettings.InstalledPrinters)
			{
				this.PrintersList.Items.Add(printerName.ToString());
			}
		}

		#endregion

		#region Print Document
		private void btnTest_Click(object sender, EventArgs e)
		{
			// Create a PrindDocument Object
			PrintDocument printDoc = new PrintDocument();
 			// Set PrinterName as the select printer in the printer list
			printDoc.PrinterSettings.PrinterName = PrintersList.SelectedItem.ToString();
    		// Add PrintPage event handler
			printDoc.PrintPage += new PrintPageEventHandler(PrintPageMethod);  
			// Print the document
			printDoc.Print(); 
		}

		public void PrintPageMethod(object sender, PrintPageEventArgs ppev)
		{
			//Get the Graphics object 
			Graphics g = ppev.Graphics;
			//Create a font verdana with size 14 
			Font font = new Font("Verdana", 20);
			//Create a solid brush with red color 
			SolidBrush brush = new SolidBrush(Color.Red);
			// Create a rectangle 
			Rectangle rect = new Rectangle(50, 50, 200, 200);
			//Draw text 
			g.DrawString("Hello, Printer! ", font, brush, rect);
		}
 
		#endregion

		private void button1_Click_1(object sender, EventArgs e)
		{
			string printerSelect = PrintersList.SelectedItem.ToString();
           
			Ticket Ticket = new Ticket(printerSelect);
            
            Ticket.TextoCentro("CORTE\n"); // imprime en el centro "Venta mostrador"
            Ticket.TextoCentro(DateTime.Now.ToString("D", new CultureInfo("es-ES"))+"\n");/// imprime en el centro "Venta mostrador"

            for (int x = 0; x <= 10; x++)
            {
                
                //Ticket.LineasGuion(); // imprime una linea de guiones
                Application.DoEvents();
                //FOLIO
                Ticket.EncabezadoVenta(x); // imprime encabezados FOLIO

                //"ALIMENTOS", BEBIDAS, EXTRAS, 
                Ticket.AgregaArticulo(152.23f, 144.54f, 21.15f); //imprime una linea de descripcion

                //SUBTOTAL, IVA, TOTAL

                // Ticket.LineasTotales(); // imprime linea 
                Ticket.AgregaTotales(152.23f, 144.54f, 21.15f); // imprime linea con total
            }
            Ticket.TextoCentro("\n\n            DATOS FISCALES"); //\n RFC \n DIRECCION \n CIUDAD \n TELEFONO \n PAGINA WEB \n\n FECHA \n FRANQUICIA \n\n"); // imprime en el centro "Venta mostrador"
            Ticket.TextoCentro("            RFC");
            Ticket.TextoCentro("            Direccion\n\n");
            Ticket.AgregaArticulo(152.23f, 144.54f, 21.15f); //imprime una linea de descripcion
            Ticket.AgregaTotales(152.23f, 144.54f, 21.15f); // imprime linea con total

            Ticket.TextoCentro("012345678901234567890123456789012345");
            Ticket.CortaTicket(); // corta el ticket
		}


        
		
	}
}
